package org.example.book.model;

import lombok.Data;
import org.example.book.enums.ResultCode;

@Data
public class Result {
    //业务状态码
    private ResultCode code;
    //错误信息
    private String errMsg;
    //数据
    private Object data;

    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS);
        result.setData(data);
        result.setErrMsg("");
        return result;
    }
    public static Result fail(String errMsg){
        Result result = new Result();
        result.setCode(ResultCode.FAIL);
        result.setErrMsg(errMsg);
        result.setData(null);
        return result;
    }
    public static Result unlogin(){
        Result result = new Result();
        result.setCode(ResultCode.UNLOGIN);
        result.setErrMsg("用户未登录");
        result.setData(null);
        return result;
    }
}
